import {
  DataTypes, STRING, JSON, BIGINT, Model
} from "sequelize";
import { sequelize } from "../../confg/db";

/** 书本表的数据模型 */
const SQL_MODEL = {
  id: {
    type: BIGINT,
    primaryKey: true,
    autoIncrement: true,
  },
  title: {
    type: STRING(100),
  },
  sub_title: {
    type: STRING(100),
  },
  content_fileld: {
    type: STRING(1000),
  },
  status: {
    type: STRING(100),
  },
  create_time: {
    type: DataTypes.DATE,
    get(this: Model) {
      const createTime =  this.getDataValue("create_time");
      return new Date(createTime).getTime();
    }
  },
  update_time: {
    type: DataTypes.DATE,
    get(this: Model) {
      const createTime =  this.getDataValue("update_time");
      return new Date(createTime).getTime();
    }
  },
};

/** 定义数据模型 */
const model = sequelize.define('paid_content', SQL_MODEL, {
  timestamps: false,
  freezeTableName: true,
});

export default model;
